package com.vooda.service.impl;

import com.vooda.dao.HomePageDao;
import com.vooda.dto.vo.BaseResult;
import com.vooda.dto.vo.HomeImagesVo;
import com.vooda.entity.HomePage;
import com.vooda.service.HomePageService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author KennyDavid
 */
@Service
public class HomePageServiceImpl implements HomePageService {

    private HomePageDao homePageDao;

    public HomePageServiceImpl(HomePageDao homePageDao) {
        this.homePageDao = homePageDao;
    }

    @Override
    public BaseResult<List<HomeImagesVo>> getRotateImages() {
        List<HomePage> images = homePageDao.findAllByStatusOrderByCreateTimeDesc(true);
        List<HomeImagesVo> dtos = new ArrayList<>();
        HomeImagesVo homeImagesVo;
        for (HomePage ho : images) {
            homeImagesVo = new HomeImagesVo();
            BeanUtils.copyProperties(ho, homeImagesVo);
            homeImagesVo.setImageUrl("https://yihubaiying.org/data_cdn/" + ho.getImageUrl());
            dtos.add(homeImagesVo);
        }
        return new BaseResult<>(dtos);
    }
}
